<?php

namespace app\logic;

use app\model\Feedback AS ModelFeedback;

class Feedback
{
    private $obj_model_name;

    private $str_model_name;

    private $str_id_name;

    public function __construct($str_model_name)
    {
        $this->str_model_name = $str_model_name;
        switch ($str_model_name) {
            case 'user': // 用户端
                $this->str_id_name = 'user_id';
                break;
            case 'courier': // 快递端
                $this->str_id_name = 'courier_id';
                break;
            case 'driver': // 司机端
                $this->str_id_name = 'driver_id';
                break;
            case 'stationapp': // 站点手机端
                $this->str_id_name = 'station_member_id';
                break;
            case 'stationpc': // 站点PC端
                $this->str_id_name = 'station_id';
                break;
            case 'admin': // CMS
                $this->str_id_name = 'admin_id';
                break;
            default:
                return false;
        }
    }

    /**
     * 新增反馈
     * @param $int_id
     * @param $str_content
     */
    public function addFeedback($int_id, $str_content)
    {
        _toCompare(empty($str_content), '==', true, 13001);

        $arr_data = [
            'client' => $this->str_model_name,
            'map_id' => $int_id,
            'is_answer' => 0,
        ];

        $int_result = ModelFeedback::getInstance()->toAdd($arr_data);

        if ($int_result > 0) _returnData();
        _returnError(10010);
    }

    /**
     * 获取反馈信息列表（后台专用）
     * @param $int_now_page
     * @param $int_list_rows
     */
    public function getFeedbackList($int_now_page, $int_list_rows)
    {
        $arr_where = [];
        $str_field = 'client,map_id,content,is_answer AS isAnswer,remark,gmt_create AS gmtCreate';
        $arr_info = Page::getInstance()->getList(ModelFeedback::getInstance(), $arr_where, $str_field, $int_now_page, $int_list_rows, null);
        _returnData($arr_info);
    }
}
